﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using MockPrjTeam4.Entity;
using MockPrjTeam4.Common;

namespace MockPrjTeam4.DAO
{
    public class CountryDAO
    {
        public static Country CountryObject(IDataRecord read)
        {
            return new Country
            {
                CountryId = Methods.ConvertNumber(read[Country.FieldCountryId].ToString()),
                CountryName = Methods.ConvertString(read[Country.FieldCountryName].ToString()),
            };
        }
        public static IList<Country> GetListCountries()
        {
            IList<Country> country = new List<Country>();
            string query = string.Format("SELECT * FROM Countries");
            IDataReader read = SqlHelper.ExecuteReader(query);
            while (read.Read())
            {
                country.Add(CountryObject(read));
            }
            return country;
        }

        public static County CountyObject(IDataReader read)
        {
            return new County
            {
                CountyId = Methods.ConvertNumber(read[County.FieldCountyId].ToString()),
                CountyName = Methods.ConvertString(read[County.FieldCountyName].ToString()),
                CountryId = Methods.ConvertNumber(read[County.FieldCountryId].ToString()),
                GovOfficeRegionId = Methods.ConvertNumber(read[County.FieldGovOfficeRegionId].ToString()),
            };
        }

        public static IList<County> GetListCouties()
        {
            IList<County> county = new List<County>();
            string query = string.Format("SELECT * FROM Counties");
            IDataReader read = SqlHelper.ExecuteReader(query);
            while (read.Read())
            {
                county.Add(CountyObject(read));
            }
            return county;
        }

        public static Town TownObject(IDataReader read)
        {
            return new Town
            {
                TownId = Methods.ConvertNumber(read[Town.FieldTownId].ToString()),
                TownName = Methods.ConvertString(read[Town.FieldTownName].ToString()),
                CountyId = Methods.ConvertNumber(read[Town.FieldCountyId].ToString()),
            };
        }

        public static IList<Town> GetListTowns()
        {
            IList<Town> town = new List<Town>();
            string query = string.Format("SELECT * FROM Towns");
            IDataReader read = SqlHelper.ExecuteReader(query);
            while (read.Read())
            {
                town.Add(TownObject(read));
            }
            return town;
        }

    }
}